<?php

namespace Addons\Cxkb\Controller;
use Home\Controller\AddonsController;
use Org\Util\Snoopy;

class CxkbController extends AddonsController{
    public function index(){
//        dump($this->get_param);
        $userinfo=M("userinfo");
        $ret=$userinfo->where($this->get_param)->find();
        if($ret>0){
            $xh=$ret["xh"];
            session("xh",$xh);
        }else{
            $this->error("还未绑定账号",addons_url("Bdjw://Bdjw/index"));
        }

//        $year=date("Y",time());
//        $month=date("m",time());
//
//        $xn[0]= ($year-1)."-".$year."-"."1";
//        if($month>=1 and $month<=7){
//            $xn=array(
//                0=>($year-1)."-".$year."-"."2",
//                1=>($year-1)."-".$year."-"."1",
//                2=>($year-2)."-".($year-1)."-"."2",
//                3=>($year-2)."-".($year-1)."-"."1",
//                5=>($year-3)."-".($year-2)."-"."2",
//                6=>($year-3)."-".($year-2)."-"."1",
//            );
//        }else{
//            $xn=array(
//                0=>($year-1)."-".$year."-"."1",
//                1=>($year-2)."-".($year-1)."-"."2",
//                2=>($year-2)."-".($year-1)."-"."1",
//                3=>($year-3)."-".($year-2)."-"."2",
//                4=>($year-3)."-".($year-2)."-"."1",
//            );
//        }

        $xqh["token"]="wxfwh";
        $xqh["wxopenid"]=get_openid();
        $sn=new Snoopy();
        $url="http://lvc.gxsdxy.cn/api/JwStuClassTable/LoadJsonMaJwStuClassTableXnxqh";
        $sn->submit($url,$xqh);
        $xn=json_decode($sn->results,true);
        $xn["rows"]=array_reverse($xn["rows"]);
        foreach ($xn["rows"] as $vo){
            if ($vo["XQBZ"]==1){
                $bxq=$vo["XNXQH"];
                $zc["start"]=$vo["QSSKZ"];
                $zc["end"]=$vo["ZZSKZ"]+1;
                break;
            }
        }

        $pkb["token"]="wxfwh";
        $pkb["wxopenid"]=$xqh["wxopenid"];
        $pkb["xh"]=$xh;
        $pkb["xnxqh"]=$bxq;
        $pkb["kbzc"]=0;
        $sn2=new Snoopy();
        $url2="http://lvc.gxsdxy.cn/api/JwStuClassTable/LoadJsonMaJwStuClassTable1";
        $sn2->submit($url2,$pkb);
        $kb=json_decode($sn2->results,true);
        $this->assign("kb",$kb["rows"])->assign("xn",$xn["rows"])->assign("zc",$zc)->assign("bxq",$bxq);
        $this->display();
    }

    public function updateKb(){

        $pkb["token"]="wxfwh";
        $pkb["wxopenid"]=get_openid();
        $pkb["xh"]=session("xh");
        $pkb["xnxqh"]=I("post.xn");
        $pkb["kbzc"]=I("post.zc");
        $sn=new Snoopy();
        $url="http://lvc.gxsdxy.cn/api/JwStuClassTable/LoadJsonMaJwStuClassTable1";
        $sn->submit($url,$pkb);
        $kb=json_decode($sn->results,true);

        $this->ajaxReturn($kb);
    }
}
